const fs = require('fs')
const path = require('path')

fs.readFile(path.join(__dirname, 'data/data.json'), (err, data) => {
  if (err) return console.log(err)
  const list = JSON.parse(data.toString())
  const womanlist = list.filter(item => item.gender === '女')
  // console.log(womanlist)
  const manlist = list.filter(item => item.gender === '男')
  fs.writeFile(path.join(__dirname, 'data/男.json'), JSON.stringify(manlist), (err) => {
    if (err) console.log(err)
    else console.log('男性写入成功')
  })
  fs.writeFile(path.join(__dirname, 'data/女.json'), JSON.stringify(womanlist), (err) => {
    if (err) console.log(err)
    else console.log('女性写入成功')
  })
})